package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.text.html.ObjectView;

/**
 * @author stone
 * @date 2022/09/01 17:27
 */
//@Controller
//@ResponseBody
@RestController
public class JsonController {

    @RequestMapping("json")
    public BaseRespVo json() {
        //return new BaseRespVo();
        //return BaseRespVo.ok("json");
        return BaseRespVo.ok("松哥牛皮");
    }

    @RequestMapping(value = "json2",produces = "text/html;charset=utf-8")
    public String json2() throws JsonProcessingException {
        BaseRespVo baseRespVo = BaseRespVo.ok("松哥牛皮");
        ObjectMapper objectMapper = new ObjectMapper();
        String value = objectMapper.writeValueAsString(baseRespVo);
        return value;
    }
}
